package org.csu.backofficemanagersys.base64;


import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

@Component
public class MD5 {
    public StringBuilder encoder(String msg) throws NoSuchAlgorithmException {
        MessageDigest m = MessageDigest.getInstance("MD5");
        m.update(msg.getBytes(StandardCharsets.UTF_8));
        byte[] s = m.digest();
        System.out.println(s);
        StringBuilder result = new StringBuilder();
        for (byte b : s) {
            result.append(Integer.toHexString((0x000000ff & b) | 0xffffff00).substring(6));
        }
        return result;
    }
}
